import md5 from 'js-md5';

// 根据ascii排序
export const sort_ascii = obj => {
	let arr = new Array();
	let num = 0;
	for (let i in obj) {
		arr[num] = i;
		num++;
	}
	let sortArr = arr.sort();
	//let sortObj = {};    //完成排序值
	let str = ''; //自定义排序字符串
	for (let i in sortArr) {
		str += sortArr[i] + '=' + obj[sortArr[i]] + '&';
	}
	//去除两侧字符串
	// let char = '&'
	// str = str.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
	return str;
}


//md5加密小写字符串
export function getMD5Screct(sign) {
	let screct = md5(sign)
	let bigScrect = screct.toLowerCase()
	return bigScrect
}

// 解析地址栏参数
export function analysisUrl(url, type) {
	var reg = new RegExp("(^|\\?|&)" + type + "=([^&]*)(\\s|&|$)", "i");
	if (reg.test(decodeURI(url))) {
		return unescape(RegExp.$2.replace(/\+/g, " ").replace("#", "").trim());
	} else {
		return "";
	}
}

export function GetLocalIPAddr() {
	var oSetting = null;
	var ip = null;
	try {
		oSetting = new ActiveXObject("rcbdyctl.Setting");
		ip = oSetting.GetIPAddress;
		if (ip.length == 0) {
			return "没有连接到Internet";
		}
		oSetting = null;
	} catch (e) {
		return ip;
	}
	return ip;
}

export const getRandom = (num) => {
	var random = Math.floor((Math.random() + Math.floor(Math.random() * 9 + 1)) * Math.pow(10, num - 1));
	return random
}
